<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="common/include :: header('合同列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            关键字：<input type="text" name="keyword"/>
                        </li>
                        <li>
                            状态：
                            <select name="auditState" th:with="type=${@dict.getType('con_audit_state')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.label}"
                                        th:value="${dict.value}"></option>
                            </select>
                        </li>
                        <li class="select-time">
                            <label>录入时间：</label>
                            <input type="text" class="timeInput" id="startTime" placeholder="年/月/日" name="beginTime"/>
                            <span>-</span>
                            <input type="text" class="timeInput" id="endTime" placeholder="年/月/日" name="endTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:post:add">
                <i class="fa fa-plus"></i> 新增
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="common/include :: footer"/>
<th:block th:include="common/include :: datetimepicker" />
<script th:inline="javascript">
    /*$('.timeInput').datetimepicker({
        format:'yyyy-mm-dd',
        autoclose:true
    });*/

    var editFlag = [[${@permission.hasPermi('system:post:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:post:remove')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var auditStateDatas = [[${@dict.getType('con_audit_state')}]];
    var affixSealStateDatas = [[${@dict.getType('con_affix_seal_state')}]];
    var nullifyStateDatas = [[${@dict.getType('con_nullify_state')}]];
    var prefix = ctx + "/business/contract";
    $(function () {
        var options = {
            url: prefix + "/query",
            createUrl: prefix + "/addPage",
            updateUrl: prefix + "/editPage?id={id}",
            removeUrl: prefix + "/remove",
            modalName: "合同",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '序号',
                    visible: true
                },
                {
                    field: 'customer.customerName',
                    title: '客户',
                    sortable: true
                },
                {
                    field: 'contractName',
                    title: '合同名称',
                    sortable: true
                },
                {
                    field: 'contractCode',
                    title: '合同编号',
                    sortable: true
                },
                {
                    field: 'amounts',
                    title: '合同金额(单位：万元)',
                    sortable: true,
                },
                {
                    field: 'startDate',
                    title: '合同开始日期',
                    sortable: true,
                },
                {
                    field: 'endDate',
                    title: '合同结束日期',
                    sortable: true,
                },
                {
                    field: 'appendix',
                    title: '电子附件',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return '<a class="btn btn-info btn-xs '+ editFlag + '" href="javascript:void(0)" onclick="downloadContract(\'' + row.id + '\')"><i class="fa fa-edit"></i>下载</a> '
                    }
                },
                {
                    field: 'inputer.userName',
                    title: '录入人',
                    sortable: true,
                },
                {
                    field: 'inputTime',
                    title: '录入时间',
                    sortable: true,
                },
                {
                    field: 'auditState',
                    title: '审核状态',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(auditStateDatas, value);
                    }
                },
                {
                    field: 'affixSealState',
                    title: '是否盖章',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(affixSealStateDatas, value);
                    }
                },
                {
                    field: 'nullifyState',
                    title: '是否作废',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(nullifyStateDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        var editClass = row.nullifyState == 1 || row.auditState != 0 || row.affixSealState == 1?'hidden':'';
                        var approveClass = row.nullifyState == 1 || row.auditState != 0 || row.affixSealState ==1? 'hidden':'';
                        var unApproveClass = row.nullifyState ==1 || row.auditState != 0 || row.affixSealState ==1 ? 'hidden':'';
                        var sureClass = row.nullifyState ==1 || row.auditState != 1 || row.affixSealState ==1 ? 'hidden':'';
                        var uselessClass = row.nullifyState == 1 || row.affixSealState == 1? 'hidden':'';
                        actions.push('<a class="btn btn-info btn-xs ' + editClass + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');


                        actions.push('<a class="btn btn-success btn-xs ' + approveClass + '" href="javascript:void(0)" ' +
                            'onclick="auditOn(\'' + row.id + '\')"><i class="fa fa-edit"></i>审核通过</a> ');

                        actions.push('<a class="btn btn-warning btn-xs ' + unApproveClass + '" href="javascript:void(0)" ' +
                            'onclick="auditOff(\'' + row.id + '\')"><i class="fa fa-edit"></i>审核不通过</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + sureClass  + '" href="javascript:void(0)"' +
                            ' onclick="affixSeal(\'' + row.id + '\')"><i class="fa fa-remove"></i>确认盖章</a>');

                        actions.push('<a class="btn btn-danger btn-xs ' + uselessClass + '" href="javascript:void(0)"' +
                            ' onclick="useless(\'' + row.id + '\')"><i class="fa fa-remove"></i>作废</a>');

                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function downloadContract(id) {
        $.modal.confirm("确定要下载吗？",function () {
            location.href = prefix + "/downloadContractMinio?id=" + id;
            /*$.get(prefix + "/downloadContract?id=" + id,function (result) {
                if (result.code == web_status.SUCCESS) {
                    $.operate.ajaxSuccess(result);
                }else {
                    $.modal.alertError(result.msg);
                }
            });*/
        })
    }

    function auditOn(id) {
        $.modal.confirm("确定审核通过吗？",function () {
            $.get(prefix + "/approve","id=" + id,function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#bootstrap-table').bootstrapTable('refresh');
                }else {
                    $.modal.alert(result.msg);
                }
            });
        })
    }

    function auditOff(id) {
        $.modal.confirm("确定审核不通过吗？",function () {
            $.get(prefix + "/unapprove","id=" + id,function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#bootstrap-table').bootstrapTable('refresh');
                }else {
                    $.modal.alert(result.msg);
                }
            });
        })
    }

    function useless(id) {
        $.modal.confirm("确定要作废吗？",function () {
            $.get(prefix + "/useless","id=" + id,function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#bootstrap-table').bootstrapTable('refresh');
                }else {
                    $.modal.alert(result.msg);
                }
            });
        })
    }

    function affixSeal(id) {
        $.modal.confirm("确定已盖章吗？",function () {
            $.get(prefix + "/affixSeal","id=" + id,function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#bootstrap-table').bootstrapTable('refresh');
                }else {
                    $.modal.alert(result.msg);
                }
            });
        })
    }
</script>
</body>
</html>